package One.创建型模式.A6建造者模式;

/**
 * @author 李某
 * * @date 2021/11/5
 * *物有本末，事有终始。知其先后者，则近道矣！
 * *荷花开满池塘的前一天还是半塘荷花半塘云。
 */
public class Builder {}

// 产品的角色
class Product{
    private String partA;
    private String partB;
    private String partC;

    public void setPartA(String partA) {
        this.partA = partA;
    }

    public void setPartB(String partB) {
        this.partB = partB;
    }

    public void setPartC(String partC) {
        this.partC = partC;
    }

    public void show(){}
}

// 抽象建造者
abstract class BuilderA{
    protected Product product = new Product();

    public abstract void buildPartA();

    public abstract void buildPartB();

    public abstract void buildPartC();

    public Product getResult(){
        return product;
    }
}

// 具体建造者
class ConcreteBuilder extends BuilderA{

    @Override
    public void buildPartA() {
        product.setPartA("建造Part A");
    }

    @Override
    public void buildPartB() {
        product.setPartB("建造Part B");
    }

    @Override
    public void buildPartC() {
        product.setPartC("建造Part C");
    }
}

// 指挥者
class Director{
    private BuilderA builderA;

    public Director(BuilderA builder){
        this.builderA = builder;
    }

    public Product construct(){
        builderA.buildPartA();
        builderA.buildPartB();
        builderA.buildPartC();
        return builderA.getResult();
    }
}

// 客户类
class Client{
    public static void main(String[] args) {
        BuilderA builderA = new ConcreteBuilder();
        Director director = new Director(builderA);
        Product product = director.construct();
        product.show();

    }
}
